package org.formal.common.utils;

import java.util.Collection;
import java.util.Map;

/**
 * string验证
 * @version:1.0
 * @Description: StringUtils
 * @author: jiangyan 
 * @date: 2018年9月25日
 */
public class StringUtils {
	/**
	 * 验证 map、null、字符串、集合、数组为空
	 * @param obj
	 * @return
	 */
	public static boolean isEmpty(Object obj) {  
        if (obj == null)  {
        	return true;  
        }
  
        if (obj instanceof CharSequence)  {
        	return ((CharSequence) obj).length() == 0;  
        }
  
        if (obj instanceof Collection) {
        	return ((Collection<?>) obj).isEmpty();  
        }
  
        if (obj instanceof Map)  {
        	return ((Map<?, ?>) obj).isEmpty();  
        }
  
        if (obj instanceof Object[]) {  
            Object[] object = (Object[]) obj;  
            if (object.length == 0) {  
                return true;  
            }  
            boolean empty = true;  
            for (int i = 0; i < object.length; i++) {  
                if (!isEmpty(object[i])) {  
                    empty = false;  
                    break;  
                }  
            }  
            return empty;  
        }  
        return false;  
    }  
	
	
	/**
	 * 验证 map、null、字符串、集合、数组不为空
	 * @param obj
	 * @return
	 */
	public static boolean isNotEmpty(Object obj) { 
		if(!isEmpty(obj)) {
			return true;  
		}
		return false;
    }  
}
